package com.leo.controller;

import com.leo.service.UserInfoService;
import com.leo.util.ApplicationContextUtil;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @ClassName: GetUserInfoController
 * @Description: ${description}
 * @Author: leo825
 * @Date: 2020-01-02 15:34
 * @Version: 1.0
 */
public class GetUserInfoController implements Controller {

    @Override
    public ModelAndView handleRequest(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
        UserInfoService userInfoService = (UserInfoService) ApplicationContextUtil.getBean("userInfoService");
        System.out.println("GetUserInfoController获取用户信息");
        ModelAndView modelAndView = new ModelAndView();
        //访问数据库
        List userInfoList = userInfoService.getUserInfoList();
        System.out.println(userInfoList);
        modelAndView.addObject("data", userInfoList);
        modelAndView.setViewName("success");//跳转到/WEB-INF/views/success.jsp
        return modelAndView;
    }
}
